package com.lite.haru.constant;

import java.util.ArrayList;
import java.util.List;

import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpParams;

import com.alibaba.fastjson.JSON;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.mapapi.SDKInitializer;
import com.lite.haru.entity.PoliceInfo;

import android.app.Activity;
import android.app.Application;
import android.app.Service;
import android.content.SharedPreferences;
import android.os.Vibrator;

public class PoliceApplication extends Application {
	public LocationService locationService;
	public Vibrator mVibrator;
	KJHttp kjh = new KJHttp();

	private SharedPreferences sp;
	private List<PoliceInfo> mData = new ArrayList<PoliceInfo>();

	public String pname;// 警察姓名
	public int police_id;// 警员id
	public String phone;// 电话
	public String province;// 省
	public String city;// 市
	public String district;// 街道

	@Override
	public void onCreate() {
		super.onCreate();
		/***
		 * 初始化定位sdk，建议在Application中创建
		 */
		locationService = new LocationService(getApplicationContext());
		mVibrator = (Vibrator) getApplicationContext().getSystemService(
				Service.VIBRATOR_SERVICE);
		// 在使用 SDK 各组间之前初始化 context 信息，传入 ApplicationContext
		SDKInitializer.initialize(this);
		sp = getSharedPreferences("AlarmPoliceinfo", Activity.MODE_PRIVATE);
		pname = sp.getString("username", "");
		forPoliceInfo();
	}
	
	private BDLocationListener mListener = new BDLocationListener() {

		@Override
		public void onReceiveLocation(BDLocation location) {
		}

	};

	public void forPoliceInfo() {

		String url = Constant.url + "/ApplicationAction";
		HttpParams params = new HttpParams();
		params.put("param0", "get_police_info");
		params.put("pname", pname);
		kjh.post(url, params, false, new HttpCallBack() {
			@Override
			public void onSuccess(String t) {

				mData = JSON.parseArray(t, PoliceInfo.class);
				for (PoliceInfo p : mData) {
					police_id = p.getId();
					pname = p.getPname();
					phone = p.getPhone();
					province = p.getProvince();
					city = p.getCity();
					district = p.getDistrict();
				}

				super.onSuccess(t);
			}

			@Override
			public void onFailure(int errorNo, String strMsg) {
				super.onFailure(errorNo, strMsg);
			}
		});
	}

}
